// 通讯录
import { ajaxService } from '@/utils/request';
import { Contacts, WsMsg, MsgParams, MsgLogParams } from './type';

const env = import.meta.env;
const baseURL = env.VITE_DEV_BASE_URL;

/**
 * 群创建
 * @param data
 * @returns
 */
export async function contactGroupCreate(data: { userId: number[] }) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/add',
    method: 'post',
    baseURL,
    data
  });
}
/**
 * 群列表
 * @param params
 * @returns
 */
export async function getContactGroupList(params: {
  pageNumber: number;
  pageSize: number;
}) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/list',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 群用户列表
 * @param params
 * @returns
 */
export async function getContactGroupUserList(params: { id: number }) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/user',
    method: 'get',
    baseURL,
    params
  });
}
interface AddGroupUserParams {
  userId: number[];
  groupId: number;
}
/**
 * 新增群成员
 * @param data
 * @returns
 */
export async function addGroupUser(data: AddGroupUserParams[]) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/invite',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 移除群成员
 * @param data
 * @returns
 */
export async function delGroupUser(data: {
  groupId: number;
  userId: number[];
}) {
  return ajaxService({
    url: `/hr/workbench/address_book/group/user`,
    method: 'delete',
    baseURL,
    data
  });
}
/**
 * 修改群信息
 * @param data
 * @returns
 */
export async function editGroupInfo(data: {
  name?: string;
  notice?: string;
  group_id: number;
}) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/update',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 群修改我的信息
 * @param data
 * @returns
 */
export async function editGroupMyInfo(data: {
  name?: string;
  notice?: string;
  groupId: number;
}) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/my/info',
    method: 'put',
    baseURL,
    data
  });
}

/**
 * 删除群聊
 * @param data
 * @returns
 */
export async function delGroup(params: { id: number }) {
  return ajaxService({
    url: `/hr/workbench/address_book/group/delete`,
    method: 'delete',
    baseURL,
    params
  });
}
/**
 * 退出群聊
 * @param data
 * @returns
 */
export async function quitGroupByGroupId(params: { id: number }) {
  return ajaxService({
    url: `/hr/workbench/address_book/group/quit`,
    method: 'delete',
    baseURL,
    params
  });
}
/**
 * 获取群基本信息，群名，公告，昵称等
 * @param params
 * @returns
 */
export async function getGroupBaseInfo(params: { id: number }) {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/group/info',
    method: 'get',
    baseURL,
    params
  });
}

/**
 * 【通讯录】常用联系人

 * @param params
 * @returns
 */
export async function getFrequentContact() {
  return ajaxService<any>({
    url: '/hr/workbench/address_book/frequent/contact',
    method: 'get',
    baseURL
  });
}

/**
 * 【标签】标识/取消标识
 * @param data
 * @returns
 */
export async function editLabel(data: { friendId?: number; isValid?: 1 | 2 }) {
  return ajaxService<any>(
    {
      url: '/hr/workbench/address_book/label/label/update',
      method: 'put',
      baseURL,
      data
    },
    { message: '修改成功', mode: 'info' }
  );
}

/**
 * 【标签】打了标签的用户id
 * @param params
 * @returns
 */
export async function getLabeList() {
  return ajaxService<number[]>({
    url: '/hr/workbench/address_book/label/label/list',
    method: 'get',
    baseURL
  });
}

/**
 * 【标签】打了标签的用户id
 * @param params
 * @returns
 */
export async function getFriendList() {
  return ajaxService<number[]>({
    url: '/hr/workbench/address_book/label/friend/list',
    method: 'get',
    baseURL
  });
}
